|
Download
FAQ History |
|
API
Search Feedback |
Web Modules
Web components and static Web content files such as images are called Web resources. A Web module is the smallest deployable and usable unit of Web resources in a J2EE application. A J2EE Web module corresponds to a Web application as defined in the Java Servlet Specification.
Web modules are typically packaged and deployed as Web archive (WAR) files. The format of a WAR file is identical to that of a JAR file. However, the contents and use of WAR files differ from JAR files, so WAR file names use a
.warextension.In addition to Web components and Web resources, a Web module can contain other files including:
The top-level directory of a Web module is the document root of the application. The document root is where JSP pages, client-side classes and archives, and static Web resources are stored.
The document root contains a subdirectory called /
WEB-INF, which contains the following files and directories:
web.xml -The Web application deployment descriptor- Tag library descriptor files (see Tag Library Descriptors)
classes- A directory that contains server-side classes: servlets, utility classes, and JavaBeans componentslib- A directory that contains JAR archives of libraries called by server-side classesYou can also create application-specific subdirectories (that is, package directories) in either the document root or the /
WEB-INF/classes/directory.The WAR structure just described is portable; you could import it into any container that conforms to the Java Servlet Specification. However, you cannot deploy it on the J2EE 1.4 Application Server until it contains a runtime deployment descriptor. The runtime deployment descriptor is an XML file that contains information such as the context root, the JNDI names of the application's resources, and some J2EE implementation-specific parameters. The J2EE application server Web application runtime DD is named
sun-web.xmland is located in /WEB-INF/along with the Web application DD.Creating a Web Module
You package Web module into a WAR using the J2EE 1.4 Application Server
deploytoolutility. To build and package thehello1application into a WAR namedhello1.war:
- In a terminal window, go to
<INSTALL>/j2eetutorial14/examples/web/hello1/.- Run
asantbuild. This target will spawn any necessary compilations and copy files to the<INSTALL>/j2eetutorial14/examples/web/hello1/build/directory.- Start
deploytool.- Create a Web application called
hello1by running the New Web Application Wizard. Select FileNew
Web Application WAR.
- New Web Application Wizard
- Select the Create New Stand-Alone WAR Module radio button.
- Click Browse and in the file chooser, navigate to
<INSTALL>/j2eetutorial14/examples/web/hello1/.- In the File Name field, enter
hello1.- Click Choose Module File.
- In the WAR Display Name field enter
hello1.- Click Edit to add the content files.
- In the Edit Contents dialog, navigate to
<INSTALL>/j2eetutorial14/examples/web/hello1/build/.Selectduke.waving.gif,GreetingServlet.class, andResponseServlet.classand click Add. Click OK.- Click Next.
- Select the Servlet radio button.
- Click Next.
- Select
GreetingServletfrom the Servlet Class combo box.- Click Finish.
- Select File
New
Web Application WAR.
- Click the Add to Existing WAR Module radio button and select
hello1from the combo box. Since the WAR contains all of the servlet classes, you do not have to add any more content.- Click Next.
- Select the Servlet radio button.
- Click Next.
- Select
ResponseServletfrom the Servlet Class combo box.- Click Finish.
A sample
hello1.waris provided in<INSTALL>/j2eetutorial14/examples/web/provided-wars/. To open this WAR withdeploytool:
|
Download
FAQ History |
|
API
Search Feedback |
All of the material in The J2EE 1.4 Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.